//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "CheckImportDataType.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TCheckImportDataTypeForm *CheckImportDataTypeForm;
//---------------------------------------------------------------------------
__fastcall TCheckImportDataTypeForm::TCheckImportDataTypeForm(TComponent* Owner)
	: TForm(Owner)
{
}

int __fastcall TCheckImportDataTypeForm::Execute(void)
{
	ShowModal();
	return Return_ID;
}

//---------------------------------------------------------------------------
void __fastcall TCheckImportDataTypeForm::AllCheckBoxClick(TObject *Sender)
{
	ProfileCheckBox->Checked = AllCheckBox->Checked;
	CurveCheckBox->Checked = AllCheckBox->Checked;
	SwitchCheckBox->Checked = AllCheckBox->Checked;
	RetarderCheckBox->Checked = AllCheckBox->Checked;
	CtrRetarderCheckBox->Checked = AllCheckBox->Checked;
	ArresterCheckBox->Checked = AllCheckBox->Checked;
	TrackRetarderCheckBox->Checked = AllCheckBox->Checked;
	CutCheckBox->Checked = AllCheckBox->Checked;
	WeatherCheckBox->Checked = AllCheckBox->Checked;
	return;
}
//---------------------------------------------------------------------------
void __fastcall TCheckImportDataTypeForm::OKButtonClick(TObject *Sender)
{
/*	int i, q, i1, q1, i2, q2, i3, q3, i4, q4;
	IXMLNode *Node, *Node1, *Node2, *Node3;//, *Node4;
	TSection Section;
	TCurve Curve;
	TSwitch Switch;
	TRetarder Retarder;
	TCtrRetarder CtrRetarder;
	TArrester Arrester;
	TTrackRetarder TrackRetarder;
	TCut Cut; TWagon Wagon;
	TRetarderList RetarderList;
	TCtrRetarderList CtrRetarderList;
	TArresterList ArresterList;
	TWagonList WagonList;
	TSwitchList SwitchList;
	TWeather W;

	Node = ImportFileXMLDocument->DocumentElement;
	if (ProfileCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("Profiles")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			Elements.Profile.clear();
			Elements.Profile.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			Elements.Profile.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			q1 = Node2->GetChildNodes()->GetCount();
			for (i1 = 0; i1 < q1; i1++) {
				Node3 = Node2->ChildNodes->Nodes[i1];     //Profile
				Section.ioLength = Node3->AttributeNodes->Nodes[WideString("Length")]->Text.ToDouble();
				Section.ioGrade = Node3->AttributeNodes->Nodes[WideString("Grade")]->Text.ToDouble();
				Section.ioRadii = Node3->AttributeNodes->Nodes[WideString("Radii")]->Text.ToDouble();
				Elements.Profile.push_back(Section);
			}
		}
	}
	if (CurveCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("Curves")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			Curve.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			Curve.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			Curve.ioBegin = Node2->AttributeNodes->Nodes[WideString("Input")]->Text.ToDouble();
			Curve.ioEnd = Node2->AttributeNodes->Nodes[WideString("Output")]->Text.ToDouble();
			Curve.Angle = Node2->AttributeNodes->Nodes[WideString("Angle")]->Text.ToDouble();
			Elements.Curves.push_back(Curve);
		}
	}
	if (SwitchCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("Switches")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			Switch.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			Switch.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			Switch.ioPosition = Node2->AttributeNodes->Nodes[WideString("Position")]->Text.ToDouble();
			Switch.ioSortRailLength = Node2->AttributeNodes->Nodes[WideString("RailLength")]->Text.ToDouble();
			Switch.ModelIndex = Node2->AttributeNodes->Nodes[WideString("ModelIndex")]->Text.ToInt();
			Switch.Model = SwitchList.Model(Switch.ModelIndex);
			Switch.Direction = Node2->AttributeNodes->Nodes[WideString("Direction")]->Text.ToInt();
			Switch.ConnectWay = Node2->AttributeNodes->Nodes[WideString("ConnectWay")]->Text.ToInt();
			Switch.DrawSide = Node2->AttributeNodes->Nodes[WideString("DrawSide")]->Text.ToInt();
			Elements.Switches.push_back(Switch);
		}
	}
	if (RetarderCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("Retarders")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			i1 = Node2->AttributeNodes->Nodes[WideString("ModelIndex")]->Text.ToInt();
			Retarder = RetarderList.Which(i1);
			Retarder.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			Retarder.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			Retarder.ioBeginPosition = Node2->AttributeNodes->Nodes[WideString("Input")]->Text.ToDouble();
			Retarder.ioEndPosition = Node2->AttributeNodes->Nodes[WideString("Output")]->Text.ToDouble();
			Retarder.Quantity = Node2->AttributeNodes->Nodes[WideString("Quantity")]->Text.ToInt();
			Retarder.Positions.InstallMode.Index = Node2->AttributeNodes->Nodes[WideString("InstallMode")]->Text.ToInt();
			Retarder.ioCriticalSpeed = Node2->AttributeNodes->Nodes[WideString("CriticalSpeed")]->Text.ToDouble();
			Retarder.ioCriticalSpeedWindage = Node2->AttributeNodes->Nodes[WideString("CriticalSpeedWindage")]->Text.ToDouble();
			Elements.Retarders.push_back(Retarder);
		}
	}
	if (CtrRetarderCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("CtrRetarders")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			i1 = Node2->AttributeNodes->Nodes[WideString("ModelIndex")]->Text.ToInt();
			CtrRetarder = CtrRetarderList.Which(i1);
			CtrRetarder.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			CtrRetarder.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			CtrRetarder.ioBeginPosition = Node2->AttributeNodes->Nodes[WideString("Input")]->Text.ToDouble();
			CtrRetarder.ioEndPosition = Node2->AttributeNodes->Nodes[WideString("Output")]->Text.ToDouble();
			CtrRetarder.Quantity = Node2->AttributeNodes->Nodes[WideString("Quantity")]->Text.ToInt();
			CtrRetarder.Positions.InstallMode.Index = Node2->AttributeNodes->Nodes[WideString("InstallMode")]->Text.ToInt();
			CtrRetarder.ioCriticalSpeed = Node2->AttributeNodes->Nodes[WideString("CriticalSpeed")]->Text.ToDouble();
			CtrRetarder.ioCriticalSpeedWindage = Node2->AttributeNodes->Nodes[WideString("CriticalSpeedWindage")]->Text.ToDouble();
			CtrRetarder.ValveType = Node2->AttributeNodes->Nodes[WideString("ValveType")]->Text.ToInt();
			CtrRetarder.BigCutQuantity = Node2->AttributeNodes->Nodes[WideString("BigCutQUantity")]->Text.ToInt();
			q1 = Node2->GetChildNodes()->GetCount();
			for (i1 = 0; i1 < q1; i1++) {
				Node3 = Node2->ChildNodes->Nodes[i1];
				CtrRetarder.SimpleControlTime[i1] = Node3->AttributeNodes->Nodes[WideString("Time")]->Text.ToDouble();
				CtrRetarder.BigCutControlled[i1] = StrToBool(Node3->AttributeNodes->Nodes[WideString("BigCut")]->Text);
			}
			Elements.CtrRetarders.push_back(CtrRetarder);
		}
	}
	if (ArresterCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("Arresters")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			i1 = Node2->AttributeNodes->Nodes[WideString("ModelIndex")]->Text.ToInt();
			Arrester = ArresterList.Which(i1);
			Arrester.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			Arrester.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			Arrester.Quantity = Node2->AttributeNodes->Nodes[WideString("Quantity")]->Text.ToInt();
			Arrester.ioPositions.InstallMode.Index = Node2->AttributeNodes->Nodes[WideString("InstallModel")]->Text.ToInt();
			q1 = Node2->GetChildNodes()->GetCount();
			Arrester.ioPositions.resize(q1);
			for (i1 = 0; i1 < q1; i1++) {
				Node3 = Node2->ChildNodes->Nodes[i1];
				Arrester.ioPositions[i1] = Node3->AttributeNodes->Nodes[WideString("ioPosition")]->Text.ToDouble();
			}
			Elements.Arresters.push_back(Arrester);
		}
	}
	if (TrackRetarderCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("TrackRetarders")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			TrackRetarder.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			TrackRetarder.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			TrackRetarder.ioBeginPosition = Node2->AttributeNodes->Nodes[WideString("Input")]->Text.ToDouble();
			TrackRetarder.ioEndPosition = Node2->AttributeNodes->Nodes[WideString("Output")]->Text.ToDouble();
			TrackRetarder.CalculateWeightLevel = Node2->AttributeNodes->Nodes[WideString("CalcilateWeightLevel")]->Text.ToInt();
			TrackRetarder.BrakeTail = Node2->AttributeNodes->Nodes[WideString("BrakeTail")]->Text.ToInt();
			TrackRetarder.BrakeTailWagonQuantity = Node2->AttributeNodes->Nodes[WideString("BrakeTailWagonQuantity")]->Text.ToInt();
			TrackRetarder.BrakeTailAxesPercent = Node2->AttributeNodes->Nodes[WideString("BrakeTailAxesercent")]->Text.ToDouble();
			q1 = Node2->GetChildNodes()->GetCount();
			for (i1 = 0; i1 < q1; i1++) {
				Node3 = Node2->ChildNodes->Nodes[i1];
				TrackRetarder.ioSpeeds.push_back(Node3->AttributeNodes->Nodes[WideString("Speed")]->Text.ToDouble());
			}
			Elements.TrackRetarders.push_back(TrackRetarder);
		}
	}
	if (CutCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("Cuts")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			i1 = Node2->AttributeNodes->Nodes[WideString("ModelIndex")]->Text.ToInt();
			Wagon = WagonList.Which(i1);
			Wagon.ioWeight = Node2->AttributeNodes->Nodes[WideString("Weight")]->Text.ToDouble();
			q1 = Node2->AttributeNodes->Nodes[WideString("Quantity")]->Text.ToInt();
			Cut.clear();
			Cut.AddWagon(Wagon, q1);
			Cut.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			Cut.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			Cut.ioInitPosition = Node2->AttributeNodes->Nodes[WideString("InitPosition")]->Text.ToDouble();
			Cut.ioDistance = Node2->AttributeNodes->Nodes[WideString("Distance")]->Text.ToDouble();
			Cut.ioStep = Node2->AttributeNodes->Nodes[WideString("Step")]->Text.ToDouble();
			Cut.ioHumpSpeed = Node2->AttributeNodes->Nodes[WideString("HumpSpeed")]->Text.ToDouble();
			Cut.PauseTime = Node2->AttributeNodes->Nodes[WideString("PauseTime")]->Text.ToDouble();
			Cut.RunType = Node2->AttributeNodes->Nodes[WideString("RunType")]->Text.ToInt();
			Cut.ioBigWheelIncreaseSpeed = Node2->AttributeNodes->Nodes[WideString("BigWheel")]->Text.ToDouble();
			Cut.PriorMeet = StrToBool(Node2->AttributeNodes->Nodes[WideString("PriorMeet")]->Text);
			Cut.Meet = StrToBool(Node2->AttributeNodes->Nodes[WideString("Meet")]->Text);
			Cut.Couple = StrToBool(Node2->AttributeNodes->Nodes[WideString("Couple")]->Text);
			Cut.TrackNumber = Node2->AttributeNodes->Nodes[WideString("TrackNumber")]->Text.ToInt();
			Elements.Cuts.push_back(Cut);
		}
	}
	if (WeatherCheckBox->Checked) {
		Node1 = Node->ChildNodes->Nodes[WideString("Weathers")];
		q = Node1->GetChildNodes()->GetCount();
		for (i = 0; i < q; i++) {
			Node2 = Node1->ChildNodes->Nodes[i];
			W.SerialNumber = Node2->AttributeNodes->Nodes[WideString("ID")]->Text;
			W.Name = Node2->AttributeNodes->Nodes[WideString("Name")]->Text;
			W.Temperature = Node2->AttributeNodes->Nodes[WideString("Temperature")]->Text.ToDouble();
			W.WindSpeed = Node2->AttributeNodes->Nodes[WideString("WindSpeed")]->Text.ToDouble();
			W.WindAngle = Node2->AttributeNodes->Nodes[WideString("WindAngle")]->Text.ToDouble();
			Elements.Weathers.Add(W);
		}
	}
	Return_ID = ID_OK;
	Close();*/
}
//---------------------------------------------------------------------------
void __fastcall TCheckImportDataTypeForm::CancelButtonClick(TObject *Sender)
{
	Return_ID = ID_CANCEL;
	Close();
}
//---------------------------------------------------------------------------

